<include file="./Public/Home/header.html" />
<div class="index">
    <div class="indexLog">
        <div class="indexTitle clear">
            <span class="indexIcon"></span>
            <span>绿贝雷快速学习特训营</span>
        </div>
        <div class="indexBtn">
            <a href="javascript:void(0)">士兵快速报名通道</a>
        </div>
    </div>
    <div class="indexContent">
        <!--<div class="select">-->
            <!--<div class="selectShow" data-id="1" onclick="selectShow(this)">-->
                <!--<div class="selectMax Camp">-->
                    <!--<input type="hidden" name="courses_id" id="courses_id" value="0">-->
                    <!--<span>请选择期数</span>-->
                <!--</div>-->
                <!--<span class="triangle"></span>-->
            <!--</div>-->
            <!--<ul class="selectList">-->
                <!--<volist name="courses" id="val">-->
                    <!--<li><a href="javascript:void(0)" data-id="{$val['id']}" data-value="{$val['id']}">{$val['name']}</a></li>-->
                <!--</volist>-->
            <!--</ul>-->
        <!--</div>-->
        <div class="indexName">
            <label>士兵</label>
            <span>姓：</span>
            <input type="text" class="surname" placeholder="张">
            <span class="nameMargin">名：</span>
            <input type="text" class="name"  placeholder="三">
        </div>
        <div class="indexPinyin">
            <label>拼音</label>
            <span>姓：</span>
            <input type="text" class="PinyinSurname" placeholder="Zhang">
            <span>名：</span>
            <input type="text" class="PinyinName"  placeholder="San">
        </div>
        <div class="indexDiv clear">
            <span>性别：</span>
            <div class="indexGender">
                <div class="selectShow" data-id="1" onclick="selectShow(this)">
                    <div class="selectMin gender">
                        <input type="hidden" name="" value="0">
                        <span>男</span>
                    </div>
                    <span class="triangle"></span>
                </div>
                <ul class="selectList">
                    <li><a href="javascript:void(0)" data-id="0">男</a></li>
                    <li><a href="javascript:void(0)" data-id="1">女</a></li>
                </ul>
            </div>
        </div>
        <div class="indexNian clear">
            <div class="indexSui ">
                <span>年龄：</span>
                <input type="text" class="age" placeholder="年龄">
            </div>
            <span>年级：</span>
            <div class="indexGrade indexAge">
                <div class="selectShow" data-id="1" onclick="selectShow(this)">
                    <div class="selectMin grade">
                        <input type="hidden" name="class_id" id="class_id" value="{$class[0]['id']}">
                        <span>{$class[0]['name']}</span>
                    </div>
                    <span class="triangle"></span>
                </div>
                <ul class="selectList"  >
                    <volist name="class" id="val">
                        <li><a href="javascript:void(0)" data-id="{$val['id']}" data-value="{$val['id']}">{$val['name']}</a></li>
                    </volist>
                </ul>
            </div>
        </div>
        <div class="heightAndWeight clear">
            <div class="indexHeight">
                <span>身高(cm)：</span><input type="text" class="height" placeholder="">
            </div>
            <div class="indexweight" style="margin: 0">
                <span>体重(kg)：</span><input type="text" class="weight"  placeholder="">
            </div>
        </div>
        <div class="indexPhone">
            <input type="text" class="phone"   placeholder="联系电话：">
            <a href="javascript:void(0)" onclick="getCode()">获取验证码</a>
        </div>
        <div class="indexCode">
            <input type="text" class="code"  placeholder="验证码：">
        </div>
        <div class="relationship">
            <span>与士兵关系：</span>
            <input type="text" class="guanXi" placeholder="如母子">
        </div>
        <div class="indexImg">
            <form id="uploadForm">
                <img src="../../../../Public/Home/images/zhao.png" alt="">
                <input type="file" name="buyer_photo" onchange="doUpload(this)" >
                <input type="hidden" id="head_img" value="">
            </form>
        </div>
        <div class="Preservation">
            <a href="javascript:void(0)" onclick="Submit()" >快速提交</a>
        </div>
    </div>
    <include file="./Public/Home/nav.html" />
</div>

<div class="mongceng">
    <div class="mengBox">
        <p>图片上传中，请稍后...</p>
    </div>
</div>

<script>
    //获取验证码
    function getCode() {
        var phone = $(".phone").val();          //获取手机号
        if (!$.trim(phone)) {
            alert_fun("请输入手机号吗！");
            return false;
        }

        $.ajax({
            url: "{:U('code')}",
            type: 'post',
            data: {
                phone:phone
            },
            dataType: "json",
            success: function (json) {
                alert_fun(json.msg);
            }
        })
    }
    //图片上传
    function doUpload(that) {
        var formData = new FormData($( "#uploadForm" )[0]);
        if (that.files && that.files[0]) {
            var kb = (that.files[0].size / 1024).toFixed(0);
            if (kb > (1024*10)) {
                alert_fun("上传大小不能超过10MB");
                return false;
            }
        }
        $(".mongceng").show();
        $.ajax({
            url: "{:U('upload')}",
            type: 'post',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType:"json",
            success: function (json) {
                $(".mongceng").hide();
                if (json.status) {
                    $("#uploadForm img").attr("src",json.data);
                    $("#head_img").val(json.data);
                } else {
                    alert_fun(json.error);
                }
            },
            error: function (returndata) {
                $(".mongceng").hide();
                alert_fun(returndata.status);
            }
        });
    }

    //快速提交
    function Submit() {
        $(".indexContent input[type='text']").each(function () {
            if (!$.trim($(this).val())) {
                alert_fun($(this).attr("data-text"));
                return false;
            }
        });
        var surname = $(".surname").val();                  //获取士兵姓
        var name = $(".name").val();                        //获取士兵名
        var PinyinSurname = $(".PinyinSurname").val();      //获取拼音姓
        var PinyinName = $(".PinyinName").val();         //获取拼音名
        var gender = $(".gender").text();                   //获取性别
        var age = $(".age").val();                         //获取年龄
        var height = $(".height").val();                    //获取身高
        var weight = $(".weight").val();                    //获取体重
        var phone = $(".phone").val();                      //获取电话
        var code = $(".code").val();                        //获取验证码
        var guanXi = $(".guanXi").val();                    //获取关系
        var class_id = $("#class_id").val();            //获取班级id
        var head_img = $("#head_img").val();            //获取用户头像

        if(surname ==''){
            alert_fun('请输入士兵姓');
            return false;
        }
        if(name ==''){
            alert_fun('请输入士兵名');
            return false;
        }
        if(PinyinSurname ==''){
            alert_fun('请输入士兵姓拼音');
            return false;
        }
        if(PinyinName ==''){
            alert_fun('请输入士兵姓拼音');
            return false;
        }

        if(age ==''){
            alert_fun('请输入年龄');
            return false;
        }

        if(class_id ==0){
            alert_fun('请选择年级');
            return false;
        }

        if(height ==''){
            alert_fun('请输入身高');
            return false;
        }
        if(weight ==''){
            alert_fun('请输入体重');
            return false;
        }
        if(phone ==''){
            alert_fun('请输入电话号码');
            return false;
        }

        if(code ==''){
            alert_fun('请输入验证码');
            return false;
        }
        if(guanXi ==''){
            alert_fun('请输入与士兵的关系');
            return false;
        }
        if(head_img ==''){
            alert_fun('请上传头像');
            return false;
        }
        $.ajax({
            url: "{:U('userUpdate')}",
            type: 'post',
            data: {
                'surname':surname,
                'name':name,
                'PinyinSurname':PinyinSurname,
                'PinyinName':PinyinName,
                'gender':gender,
                'age':age,
                'height':height,
                'weight':weight,
                'phone':phone,
                'code':code,
                'guanXi':guanXi,
                'class_id':class_id,
                'head_img':head_img
            },
            dataType: "json",
            success: function (json) {
                if (json.status) {
                    window.location.href="{:U('Home/UserCenter/center')}"+'?orderId='+json.orderId;
                } else {
                    alert_fun(json.error);
                }
            }
        })
    }


</script>
    <include file="./Public/Home/footer.html" />
